
import java.io.IOException;
import java.util.ArrayList;

import org.apache.commons.math3.stat.correlation.*;
import org.apache.commons.math3.stat.regression.SimpleRegression;
import org.apache.commons.math3.stat.regression.SimpleRegression.*;


public class Regression {
	private ArrayList<Double>rawData;
	private ArrayList<Double>NASDAQRaw;
	private ArrayList<Double>againstNASDAQ = new ArrayList<Double>();
	private double[]passingRaw;
	private double[]passingStock;
	int smallerStock=0;
	int startCorRange=0;
	int endCorRange=0;
	double regressionIntercept=0;
	double regressionSlope=0;
	SimpleRegression linearRegression = new SimpleRegression(true);
	PearsonsCorrelation calcAgainstNASDAQ = new PearsonsCorrelation();
	String featureList[] = { "NASDAQIndex", "DJIAIndex", "Nikkei225",
			"S&P500Index", "DAXIndex", "FTSEIndex", "CACIndex", "SHANGHAIIndex", "HANGIndex"  };
	
	
	public Regression(ReadingDataFromCSV temp) throws IOException{
		NASDAQRaw=temp.getStockData().get(0);
		//System.out.println(NASDAQRaw.size());
	
		for(int i=0; i<9;i++){
			
			rawData=temp.getStockData().get(i);
			smallerStock=Math.min(rawData.size(),NASDAQRaw.size());
			passingRaw= new double[smallerStock];
			passingStock= new double[smallerStock];
			endCorRange=smallerStock;
			endCorRange=21;
			//startCorRange=endCorRange-daysPrior;
			
			for(int a=1;a<endCorRange;a++){
				passingRaw[a]=NASDAQRaw.get(a);
				passingStock[a]=rawData.get(a);
				linearRegression.addData(passingRaw[a],passingStock[a]);
			}
			
			regressionIntercept=linearRegression.getIntercept();
			regressionSlope=linearRegression.getSlope();

			System.out.println(featureList[i]+" regression: y = "+regressionSlope+"x + "+regressionIntercept);
			
		}
		System.out.println();
		
		}
	
		
	}

